<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .boss {
            width: 400px;
            height: 400px;
            background-color: pink;
        }

        .boxOne {
            width: 400px;
            height: 300px;
            background-color: skyblue;
        }

        .boxOne img {
            width: 100%;
            height: 100%;
        }

        .boxTow {
            width: 400px;
            height: 100px;
            background-color: green;
        }

        .title {
            width: 300px;
            height: 100px;
            background-color: wheat;
        }
    </style>
</head>

<body>
    <div class="boss">
        <div class="boxOne">
            <img src="" alt="">
        </div>
        <div class="boxTow">
            <div class="title">
                <p id="p"></p>
            </div>
            <div class="botton"></div>
        </div>
    </div>
</body>
<script>
    const sliderData = [
        { url: './img/slider01.jpg', title: '对人类来说会不会太超前了？', color: 'rgb(100, 67, 68)' },
        { url: './img/slider02.jpg', title: '开启剑与雪的黑暗传说！', color: 'rgb(43, 35, 26)' },
        { url: './img/slider03.jpg', title: '真正的jo厨出现了！', color: 'rgb(36, 31, 33)' },
        { url: './img/slider04.jpg', title: '李玉刚：让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },
        { url: './img/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },
        { url: './img/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
        { url: './img/slider07.jpg', title: '一站式解决你的电脑配置问题！！！', color: 'rgb(53, 29, 25)' },
        { url: './img/slider08.jpg', title: '谁不想和小猫咪贴贴呢！', color: 'rgb(99, 72, 114)' },
    ];
    let imgs = document.querySelector('.boxOne img');
    console.log(imgs);

    // 步骤
    // 1.随机生成1-8的数
    // 2.拿到对应数组对象的值，设置对象内容

    let random = Math.floor(Math.random() * 8);
    //拿到下标所对应的对象
    let setSlider = sliderData[random];
    // 拿下标对应的图片路径
    let urls = setSlider.url;
    console.log(urls);
    // 拿下标对应的标题
    let p = document.querySelector('.title p');
    // 设置对应的标题
    let title = setSlider.title;
    //设置标题
    p.innerHTML = title;
    // 设置图片
    imgs.src = urls;

</script>

</html>